﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MapViewer.Model
{
	[Loaders.LoaderType(LoaderType=typeof(Loaders.UrlLoader))]
	class UrlRecentItem : RecentItem
	{
		public String Url { get; set; }

		public override string Title
		{
			get
			{
				if (Url.Length == 0)
					return Url;
				Uri uri = new Uri(Url, UriKind.Absolute);
				string path = uri.AbsolutePath.Substring(1);
				if (uri.AbsoluteUri.Length > 100)
				{
					string root = uri.AbsoluteUri;
					root = root.Substring(0, root.IndexOf(path));
					path = path.Substring(path.Length - 101 + root.Length);
					return root + "…" + path;
				}
				return uri.AbsoluteUri;
			}
		}

		internal override void ParseValue(string definition)
		{
			Url = definition;
		}

		public override string Definition
		{
			get
			{
				return base.Definition + Url;
			}
		}
	}
}
